package msg.udp;

import msg.view.ClientView;


public class UDPClient extends Thread {

	private UDPSocket udp;
	private ClientView clientView;
	private boolean flag;
	private int port;


	public UDPClient(ClientView clientView) {
		this.udp = new UDPSocket();
		this.clientView = clientView;
		this.flag = true;
		this.port = 54000;
	}


	public int getLocalPort() {
		for (int i = 0; i < 100; i++) {
			this.port += i;

			if (this.udp.addReceiveSocket(this.port)) {
				return this.port;
			}
		}
		return 0;
	}


	public void run() {
		while (this.flag) {
			this.clientView.setTxtBox(this.udp.receive());
		}
	}
}
